// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

let element = ['voice', 'image', 'text', 'phiz', 
// 'many'
];//基本元素
let eleJson = {
  voice: [{ text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test01.mp3', ceart: 'voice', duration: 6 }, { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test02.mp3', ceart: 'voice', duration: 3 }, { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/小朋友.mp3', ceart: 'voice',duration: 21 }, { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test04.mp3', ceart: 'voice', duration: 5 }, { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test03.mp3', ceart: 'voice',duration: 3 },],
  image: [
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/biubiubiu.gif', ceart: 'image', width: 300, height: 300 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test01.jpg', ceart: 'image', width: 480, height: 360 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test02.jpg', ceart: 'image', width: 635, height: 635 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test03.jpg', ceart: 'image', width: 635, height: 635 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test04.jpg', ceart: 'image', width: 600, height: 600 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test05.jpg', ceart: 'image', width: 240, height: 240 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test06.gif', ceart: 'image', width: 300, height: 258 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test07.jpg', ceart: 'image', width: 827, height: 635 },
    
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/01.gif', ceart: 'image', width: 640, height: 557 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/02.gif', ceart: 'image', width: 640, height: 521 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/03.gif', ceart: 'image', width: 640, height: 360 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/04.gif', ceart: 'image', width: 827, height: 635 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/05.gif', ceart: 'image', width: 200, height: 271 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/06.gif', ceart: 'image', width: 177, height: 150 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/07.gif', ceart: 'image', width: 449, height: 449 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/08.gif', ceart: 'image', width: 300, height: 210 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/09.gif', ceart: 'image', width: 640, height: 367 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/10.gif', ceart: 'image', width: 489, height: 180 },
    { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/12.gif', ceart: 'image', width: 300, height: 300 },
    ],
  text: [{
    text: '这种事情见得多了，我只想说懂得都懂，不懂的我也不多解释，毕竟自己知道就好，细细品吧。你们也别来问我怎么了，利益牵扯太大，说了对你我都没好处，当不知道就行了，其余的我只能说这里面水很深，牵扯到很多东西。详细情况你们自己是很难找的，网上大部分已经删除干净了，所以我只能说懂得都懂。', ceart: 'text'
  }, { text: '把嘴给我闭上!38块钱…再送一个老头!!。', ceart: 'text' }, { text: '不会吧，不会吧？不会真的有人会说不会吧，不会吧，不会吧？', ceart: 'text' }, { text: '这个作者很菜，写的程序老是出现Bug。', ceart: 'text' }, { text: '动物园里有大西几！小凶许！小脑斧！梅发怒！小福泥！小海疼！发福蝶！大鸡居！大飞囊！大来流！强颈怒！大蟒鞋！小白去！鸵寮！大带许！大穷猫！大诺坨！大你鱼！丹鼎货！小乌堆！小蜜哄！小猴几！小脑许！毛毛穷！大姜鱼！', ceart: 'text' }, {
    text: '蒸羊羔,蒸熊白掌,蒸鹿尾儿,烧花鸭, 烧雏鸡儿, 烧子鹅肚, 卤煮咸鸭, 酱鸡子, 腊肉, 松花, 小肚儿肚, 晾肉, 香肠, 什锦苏盘,熏鸡, 白肚儿, 清蒸八宝猪, 江米酿鸭子,罐儿野鸡, 罐儿鹌鹑,卤什锦, 卤子鹅, 卤虾, 烩虾, 炝虾仁儿, 山鸡, 兔脯, 菜蟒, 银鱼, 清蒸哈什蚂, 烩鸭腰儿, 烩鸭条儿, 清拌鸭丝儿, 黄心管儿,焖白鳝, 焖黄鳝, 豆鼓鲇鱼, 锅烧鲇鱼, 烀皮甲鱼, 锅烧鲤鱼, 抓炒鲤鱼,软炸里脊, 软炸鸡, 什锦套肠, 麻酥油卷儿,熘鲜蘑, 熘鱼脯儿, 熘鱼片儿, 熘鱼肚儿, 醋熘肉片儿, 熘白蘑,烩三鲜, 炒银鱼, 烩鳗鱼, 清蒸火腿, 炒白虾, 炝青蛤, 炒面鱼,炝芦笋, 芙蓉燕菜, 炒肝尖儿, 南炒肝关儿, 油爆肚仁儿, 汤爆肚领儿,炒金丝, 烩银丝, 糖熘饹炸儿, 糖熘荸荠, 蜜丝山药, 拔丝鲜桃。', ceart: 'text' }],
  phiz: [{ text: '别瞎搞了，作者已经哭晕在厕所里了[流泪][流泪][流泪]', ceart: 'phiz' }, { text: '[微笑][微笑][微笑]', ceart: 'phiz' }],
  // many: [{}],
};
let specialList = [
  { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/NetEase.mp3', ceart: 'voice', duration: 72 },
  { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/qq.jpg', ceart: 'image', width:540,height:400  }, 
  { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/wechat.gif', ceart: 'image', width: 400, height: 400 },
  { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/zsm.jpg', ceart: 'image', width: 635, height: 635 }
  ,   { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/白蛇：缘起BD_02.mp4', ceart: 'video' }];//特别难触碰 视频、二维码、超链接、
let seekList = [{ text:'https://blog.csdn.net/ceart',ceart: 'herf' },
 { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/wz.mp3', ceart: 'voice', duration: 3 },
  {}, {}, {}];//用户正则查找
let NetEase = [{ text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/NetEase.mp3', ceart: 'voice', duration: 72 }, { text: 'https://6365-ceart-d4onv-1301709499.tcb.qcloud.la/static/audio/test05.mp3', ceart: 'voice', duration: 2 }, { text: '《人间失格》里有这么一句话：“你在此地不要走动，我去给你买袋橘子。”', ceart: 'text' }, { text: '生不出人，我很抱歉。', ceart: 'text' },];//网抑云

// 云函数入口函数
exports.main = async (event, context) => {
  let res = {};
  let info = encodeURIComponent(event.info);
  function special(index) {
    return specialList[index];
  }
  if (event.ai=='skin'){
  
    let eleIndex = Math.floor(Math.random() * element.length);
    
    if (eleIndex == element.length) {
      res =special(eleIndex)
    } else {
      let eleKey = element[eleIndex];
      let eleIdx = Math.round(Math.random() * eleJson[eleKey].length);
      res = eleIdx == eleJson[eleKey].length ? special(eleIndex) : eleJson[eleKey][eleIdx];
    }

  } else if (event.ai == 'netEas'){
    let netIndex = Math.floor(Math.random() * NetEase.length);
    if (netIndex == NetEase.length) {
      res = special(netIndex)
    } else {
      res = NetEase[netIndex];
    }

  }
  res.playStatus = false;

  return res;
}